package com.dinggou.shopjb.view;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Process;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.dinggou.shopjb.R;
import com.dinggou.shopjb.activitys.WebViewActivity;
import com.dinggou.shopjb.application.MyApplication;
import com.dinggou.shopjb.constants.Constant;
import com.dinggou.shopjb.core.AppAction;


public class PrivateConfirmDialog extends MyDialog implements View.OnClickListener {

    private View rootView;
    private TextView tv_user_url;
    private TextView tv_private_url;
    private TextView tv_cancel;
    private TextView tv_confirm;
    protected AppAction mAppAction;


    public PrivateConfirmDialog(Context context, PrivateConfirmListener listener) {
        this(context, false, Gravity.CENTER,listener);
    }

    public PrivateConfirmDialog(Context context, boolean isCancelAble, int gravity, PrivateConfirmListener listener) {
        super(context, isCancelAble, gravity);
        this.mListener = listener;
        mAppAction = MyApplication.getApplication().getAppAction();
        rootView = LayoutInflater.from(context).inflate(R.layout.dialog_private, null);
        setContentView(rootView);

        tv_user_url = rootView.findViewById(R.id.tv_user_url);
        tv_private_url = rootView.findViewById(R.id.tv_private_url);
        tv_cancel = rootView.findViewById(R.id.tv_cancel);
        tv_confirm = rootView.findViewById(R.id.tv_confirm);


        tv_user_url.setOnClickListener(this);
        tv_private_url.setOnClickListener(this);
        tv_cancel.setOnClickListener(this);
        tv_confirm.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        Bundle bundle;
        switch (v.getId()) {
            case R.id.tv_user_url:
                bundle = new Bundle();
                bundle.putString("url", Constant.H5_USER_URL);
                gotoActivity(mContext, WebViewActivity.class, bundle);
                break;
            case R.id.tv_private_url:
                bundle = new Bundle();
                bundle.putString("url", Constant.H5_PRIVATE_URL);
                gotoActivity(mContext, WebViewActivity.class, bundle);
                break;
            case R.id.tv_cancel:
                dismiss();
                Process.killProcess(Process.myPid());
                break;
            case R.id.tv_confirm:
                dismiss();
                mListener.onConfirmListener();
                break;
        }
    }


    public void gotoActivity(Context mContext, Class<?> toActivityClass, Bundle bundle) {
        Intent intent = new Intent(mContext, toActivityClass);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        mContext.startActivity(intent);
        ((Activity) mContext).overridePendingTransition(R.anim.push_right_in, R.anim.not_exit_push_left_out);
    }


    private PrivateConfirmListener mListener;

    public interface PrivateConfirmListener {
        void onConfirmListener();
    }
}
